#include <fcntl.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>

int main() {
    int fd = open("test.txt", O_RDWR | O_CREAT, 0666);
    if (fd == -1) {
        perror("open failed");
        exit(1);
    }
    int new_fd = fcntl(fd, F_DUPFD, 10); // 复制文件描述符，新描述符>=10
    if (new_fd == -1) {
        perror("fcntl F_DUPFD failed");
        exit(1);
    }
    if (write(new_fd, "Hello, fcntl!\n", 14) == -1) {
        perror("write failed");
        exit(1);
    }
    close(fd);
    close(new_fd);
    return 0;
}
